package com.wanshi.member.exception;

import com.wanshi.member.base.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class MyExceptionHandler {

    /**
     * 自定义的异常
     * @param e
     * @return
     */
    @ExceptionHandler(MyException.class)//指定异常类型
    @ResponseBody
    public Result handleMyException(MyException e) {
        e.printStackTrace();
        return Result.error(e.getMessage());
    }


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result globalError(Exception e) {
        e.printStackTrace();
        return Result.error("未知错误");
    }


}
